package com.financing.wap.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.financing.wap.common.SessionUtil;
import com.financing.wap.dao.IActivitiesMollionsWealthDao;
import com.financing.wap.dao.IFpFundInfoDao;
import com.financing.wap.dto.ActivitesMollionsWealthDTO;
import com.financing.wap.dto.FpFundInfoDTO;
import com.financing.wap.dto.FpVideoDTO;
import com.financing.wap.dto.ProductDTO;
import com.financing.wap.service.IFpFundInfoService;
import com.financing.wap.service.IFpVideoService;

/**
 * @Description:Service实现类
 * @version 1.0
 * @created caojiayao
 */
 
@Service(value="fpFundInfoService")
public class FpFundInfoServiceImpl implements IFpFundInfoService {

	/**
	 * 日志类
	 */
	protected  static Logger log = Logger.getLogger(FpFundInfoServiceImpl.class);
	
    @Autowired
	private IFpFundInfoDao fpFundInfoDao;
    
	@Autowired
	private IActivitiesMollionsWealthDao activitiesMollionsWealthDao;
	
	@Autowired
	private IFpVideoService fpVideoService;
	
	@Override
	public FpFundInfoDTO getFpFundInfo(Integer id) {
		 FpFundInfoDTO fpFundInfoDTO = fpFundInfoDao.getFpFundInfo(id);
		try {
			//产品列表-新增 活动关联
			ActivitesMollionsWealthDTO activitesMollionsWealthDTO = new ActivitesMollionsWealthDTO();
			activitesMollionsWealthDTO.setpId(fpFundInfoDTO.getId());
			activitesMollionsWealthDTO.setpType("01");
			fpFundInfoDTO.setActivitiesMollionsWealthList(activitiesMollionsWealthDao.queryActivitiesMollionsWealthList(activitesMollionsWealthDTO));
		} catch (Exception e) {
			log.error("getProductList queryActivitiesMollionsWealthList error",e);
		}
		
		try {
			//添加 视频路演id
			FpVideoDTO  queryVideo = new FpVideoDTO();
			queryVideo.setProductType("01");//私募
			queryVideo.setProductId(fpFundInfoDTO.getId());
			queryVideo = fpVideoService.queryVideoInfo(queryVideo);
			
			/*//session 未空的时候 ，清空 视频密码
			if(SessionUtil.getSession(true).getUser() == null && queryVideo != null){
				queryVideo.setEncryptionPassword(null);
			}*/
			
			fpFundInfoDTO.setSfaVideo(queryVideo);
		} catch (Exception e) {
			log.error("fpVideoService queryVideoInfo error",e);
		}
		
		return fpFundInfoDTO;
	}
	
	
	@Override
	public Integer insertFpFundInfo(FpFundInfoDTO dto) {
		return fpFundInfoDao.insertFpFundInfo(dto);
	}

	
	@Override
	public Integer updateFpFundInfo(FpFundInfoDTO dto) {
		return fpFundInfoDao.updateFpFundInfo(dto);
	}
	
	@Override
	public Integer delFpFundInfo(Integer id) {
		return fpFundInfoDao.delFpFundInfo(id);
	}
	
	@Override
	public List<FpFundInfoDTO> listFpFundInfo(FpFundInfoDTO dto) {
		 List<FpFundInfoDTO> listFpFundInfo = fpFundInfoDao.listFpFundInfo(dto);
		for (FpFundInfoDTO fpFundInfoDTO : listFpFundInfo) {
			try {
				//产品列表-新增 活动关联
				ActivitesMollionsWealthDTO activitesMollionsWealthDTO = new ActivitesMollionsWealthDTO();
				activitesMollionsWealthDTO.setpId(fpFundInfoDTO.getId());
				activitesMollionsWealthDTO.setpType("01");
				fpFundInfoDTO.setActivitiesMollionsWealthList(activitiesMollionsWealthDao.queryActivitiesMollionsWealthList(activitesMollionsWealthDTO));
			} catch (Exception e) {
				log.error("getProductList queryActivitiesMollionsWealthList error",e);
			}
			
			try {
				//添加 视频路演id
				FpVideoDTO  queryVideo = new FpVideoDTO();
				queryVideo.setProductType("01");//私募
				queryVideo.setProductId(fpFundInfoDTO.getId());
				queryVideo = fpVideoService.queryVideoInfo(queryVideo);
				
				//session 未空的时候 ，清空 视频密码
				/*if(SessionUtil.getSession(true).getUser() == null && queryVideo != null){
					queryVideo.setEncryptionPassword(null);
				}*/
				
				fpFundInfoDTO.setSfaVideo(queryVideo);
			} catch (Exception e) {
				log.error("fpVideoService queryVideoInfo error",e);
			}
		}
		return listFpFundInfo;
	}
	
	@Override
	public Integer countFpFundInfo(FpFundInfoDTO dto){
		return fpFundInfoDao.countFpFundInfo(dto);
	}
	
	public List<FpFundInfoDTO> listFpFundInfoByCompanyId(String CompanyId){
		return fpFundInfoDao.listFpFundInfoByCompanyId(CompanyId);
	}
	
	public List<FpFundInfoDTO> listFpFundInfoByManagerId(String ManagerId){
		return fpFundInfoDao.listFpFundInfoByManagerId(ManagerId);
	}


	@Override
	public FpFundInfoDTO countFpFundInfoByzt() {
		return fpFundInfoDao.countFpFundInfoByzt();
	}


	@Override
	public String fpFpFundInfoLSJZ(FpFundInfoDTO dto) {
		return fpFundInfoDao.fpFundInfoLSJZ(dto);
	}


	@Override
	public List<ProductDTO> listFpFundInfoByType() {
		return fpFundInfoDao.listFpFundInfoByType();
	}


	@Override
	public FpFundInfoDTO loadById(Integer id) {
		FpFundInfoDTO fpFundInfoDTO = fpFundInfoDao.getFpFundInfo(id);
		return fpFundInfoDTO;
	}
}
